﻿@model CompetitionViewModel

@{ var routeValues = new { area = "CompetitionArea", id = Model.CompetitionSearchResultViewModel.Competition.Pk }; }

@if (Model.CompetitionSearchResultViewModel.IsVisible)
{
    <section>
        
        @Html.DisplayFor(m => m.CompetitionSearchResultViewModel, "CompetitionHeader")

        <div class="grid_12 clearfix">
            @Html.Partial("_DbType")
        </div>

        @if (Model.LeagueTable != null)
        {

            <div class="grid_8">
                <table style="font-size: 1.1em;">
                    <thead>
                        <tr>
                            <th colspan="8" class="ctl">League table</th>
                        </tr>
                    </thead>

                    <tr>
                        <td>&nbsp;</td>
                        <td class="ctl">P</td>
                        <td class="ctl">W</td>
                        <td class="ctl">D</td>
                        <td class="ctl">L</td>
                        <td class="ctl">F</td>
                        <td class="ctl">A</td>
                        <td class="ctl">Pts</td>
                    </tr>

                    @foreach (var item in Model.LeagueTable)
                    {
                        <tr>
                            <td>
                                <a href="@Url.Action("Index", "Details", new { area = "TeamArea", id = item.TeamVersion.Pk })">@item.TeamVersion.TeamName</a>
                            </td>

                            <td class="ctl">@item.Played</td>
                            <td class="ctl">@item.Wins</td>
                            <td class="ctl">@item.Draws</td>
                            <td class="ctl">@item.Losses</td>
                            <td class="ctl">@item.Scored</td>
                            <td class="ctl">@item.Conceded</td>
                            <td class="ctl">@item.Points</td>
                        </tr>
                    }
                </table>
            </div>

            <div class="grid_4 clearfix">
                <table>
                    <thead>
                        <tr>
                            <th colspan="3" class="ctl">Latest results</th>
                        </tr>
                    </thead>

                    @foreach (var group in Model.Matches.GroupBy(m => m.MatchDate.Date).Take(3))
                    {
                        DateTime matchDate = group.FirstOrDefault().MatchDate;
                    
                        <tr>
                            <th colspan="3" class="ctl">@matchDate._ToDisplayString()</th>
                        </tr>
                    
                        foreach (var match in group)
                        {
                            <tr>
                                <td class="rtl">
                                    <a href="@Url.Action("Index", "Details", new { area = "TeamArea", id = match.TeamVersion1.Pk })">@match.TeamVersion1.TeamName</a>
                                </td>
                        
                                <td class="ctl" style="width: 1px">
                                    <a href="@Url.Action("Index", "Details", new { area = "MatchArea", id = match.Pk })">@string.Format("{0}-{1}", match.Team1FT, match.Team2FT)</a>
                                

                                </td>
                        
                                <td style="width: 1px">
                                    <a href="@Url.Action("Index", "Details", new { area = "TeamArea", id = match.TeamVersion2.Pk })">@match.TeamVersion2.TeamName</a>
                                </td>
                            </tr>
                        }
                    }
                </table>
            </div>
        }
    </section>
}